package com.zbkj.service.service.ai.utils;

public class UniToStrUtil {

    //将\\u开头的unicode字符串转换为中文
    public static String unicodeToString(String unicodeStr){
        StringBuilder sb = new StringBuilder();
        int i = -1;
        int pos = 0;
        //在pos及之后搜索\\u
        while((i = unicodeStr.indexOf("\\u", pos)) != -1) {
            sb.append(unicodeStr.substring(pos, i));

            if((i+5) < unicodeStr.length()){
                String unicode = unicodeStr.substring(i + 2, i + 6);
                sb.append((char) Integer.parseInt(unicode, 16));
                pos = i + 6;
            } else {
                sb.append(unicodeStr.substring(i, unicodeStr.length()));
                return sb + "";
            }
        }
        return sb + "" + unicodeStr.substring(pos, unicodeStr.length());
    }

}
